<?php

/**
 * This is the model class for table "{{goods}}".
 *
 * The followings are the available columns in table '{{goods}}':
 * @property string $goods_id
 * @property string $goods_sn
 * @property string $goods_name
 * @property string $goods_brief
 * @property string $goods_desc
 * @property integer $cat_id
 * @property integer $brand_id
 * @property string $market_price
 * @property string $shop_price
 * @property string $promote_price
 * @property string $promote_start_time
 * @property string $promote_end_time
 * @property string $goods_img
 * @property string $goods_thumb
 * @property integer $goods_number
 * @property string $click_count
 * @property integer $type_id
 * @property integer $is_promote
 * @property integer $is_best
 * @property integer $is_new
 * @property integer $is_hot
 * @property integer $is_onsale
 * @property string $add_time
 */
class Goods extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{goods}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('cat_id, brand_id, goods_number, type_id, is_promote, is_best, is_new, is_hot, is_onsale', 'numerical', 'integerOnly'=>true),
			array('goods_sn', 'length', 'max'=>30),
			array('goods_name', 'length', 'max'=>100),
			array('goods_brief', 'length', 'max'=>255),
			array('market_price, shop_price, promote_price, promote_start_time, promote_end_time, click_count, add_time', 'length', 'max'=>10),
			array('goods_img,goods_thumb', 'length', 'max'=>350),
			array('goods_desc', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('goods_id, goods_sn, goods_name, goods_brief, goods_desc, cat_id, brand_id, market_price, shop_price, promote_price, promote_start_time, promote_end_time, goods_img, goods_thumb, goods_number, click_count, type_id, is_promote, is_best, is_new, is_hot, is_onsale, add_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
				'category'=>array(self::BELONGS_TO,'Category','cat_id'),
				'brand'=>array(self::BELONGS_TO,'Brand','brand_id'),
		);
	}	

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'goods_id' => 'Goods',
			'goods_sn' => 'Goods Sn',
			'goods_name' => '商品名称',
			'goods_brief' => 'Goods Brief',
			'goods_desc' => '商品详细描述',
			'cat_id' => '商品分类',
			'brand_id' => '商品品牌',
			'market_price' => 'Market Price',
			'shop_price' => '商品价格',
			'promote_price' => 'Promote Price',
			'promote_start_time' => 'Promote Start Time',
			'promote_end_time' => 'Promote End Time',
			'goods_img' => '商品图片',
			'goods_thumb' => '缩略图',
			'goods_number' => 'Goods Number',
			'click_count' => 'Click Count',
			'type_id' => 'Type',
			'is_promote' => 'Is Promote',
			'is_best' => 'Is Best',
			'is_new' => 'Is New',
			'is_hot' => 'Is Hot',
			'is_onsale' => 'Is Onsale',
			'add_time' => 'Add Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('goods_id',$this->goods_id,true);
		$criteria->compare('goods_sn',$this->goods_sn,true);
		$criteria->compare('goods_name',$this->goods_name,true);
		$criteria->compare('goods_brief',$this->goods_brief,true);
		$criteria->compare('goods_desc',$this->goods_desc,true);
		$criteria->compare('cat_id',$this->cat_id);
		$criteria->compare('brand_id',$this->brand_id);
		$criteria->compare('market_price',$this->market_price,true);
		$criteria->compare('shop_price',$this->shop_price,true);
		$criteria->compare('promote_price',$this->promote_price,true);
		$criteria->compare('promote_start_time',$this->promote_start_time,true);
		$criteria->compare('promote_end_time',$this->promote_end_time,true);
		$criteria->compare('goods_img',$this->goods_img,true);
		$criteria->compare('goods_thumb',$this->goods_thumb,true);
		$criteria->compare('goods_number',$this->goods_number);
		$criteria->compare('click_count',$this->click_count,true);
		$criteria->compare('type_id',$this->type_id);
		$criteria->compare('is_promote',$this->is_promote);
		$criteria->compare('is_best',$this->is_best);
		$criteria->compare('is_new',$this->is_new);
		$criteria->compare('is_hot',$this->is_hot);
		$criteria->compare('is_onsale',$this->is_onsale);
		$criteria->compare('add_time',$this->add_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Goods the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
